package com.pw.ba.base.controller;


import com.pw.ba.base.pojo.Order;
import com.pw.ba.base.service.SearchOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/order")
public class SearchOrderController {

    @Autowired
    SearchOrderService searchOrderService;

    @GetMapping("/search")
    public List<Order> searchOrder(@RequestParam("userId") String userId){

        System.out.println(userId);
        ArrayList list = searchOrderService.searchOrder(userId);
        for (int i = 0; i <list.size() ; i++) {
            Order order = (Order) list.get(i);
            if (order.getStatus().equals("1")){
                order.setStatus("交易成功");
            }
            else if (order.getStatus().equals("2")){
                order.setStatus("交易取消");
            }
            else if (order.getStatus().equals("3")){
                order.setStatus("退款成功");
            }
            else if (order.getStatus().equals("4")){
                order.setStatus("退款中");
            }
            else if (order.getStatus().equals("5")){
                order.setStatus("待付款");
            }
            System.out.println(order);
        }

        return list;

    }

}
